<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
		<link rel="stylesheet" type="text/css" href="css/layer.css"/>
		<script src="js/jquery.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/layer.js"></script>
		<script src="js/jq.cookie.js"></script>
	</head>
	
	<style>
		body{
			width: 100%;
			text-align: center;
		}
		table{
			width: 90%;
			margin-left: 5%;
			margin-top: 10px;
		}
		tr{
			height: 30px;
			font-size: 12px;
			
		}
		td,th{
			border: solid 1px #C7C7C7;
			font-weight: normal;
			text-align: center;
			position: relative;
		}
		td input{
			position: absolute;
			left:20px;
		}
		.btn{
			margin-top: 20px;
		}
		.qu_name{
			padding-left: 30px;
		}
	</style>
	<body>
		<table>
			<thead>
				<tr>
					
					<th style="min-width:100px ;">名称</th>
					<th style="width: 80px;">金额</th>
					<th>使用条件</th>
					<th>有效期</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
		</table>
		 <input type="button" class="btn save_btn" value="添加"/>
		
	</body>
</html>
<script>
function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
		var orderNum = GetQueryString('num');
		var Kind = GetQueryString('Kind');
		
		if(Kind==1){//发券
			$.ajax({
				type:"get",
				url:"https://www.retux.cn/MgUserSendCoupon",
				async:true,
				success:function(data){
					for (var i=0;i<data.length;i++) {
						var Tr = `
						<tr> 
							<td class="qu_name"><input type="checkbox" num = "${data[i][4]}">${data[i][0]}</td>
							<td>${data[i][1]}</td>
							<td>${data[i][2]}</td>
							<td>${data[i][3]}</td>
						</tr>
						
					`;
					$("tbody").append(Tr)
					}
					
				}
			});
			
			$('.save_btn').click(function(){
					var Check = [];
					for (var i = 0;i<$("table").find("input").length;i++) {
						if($("table").find("input").eq(i).prop("checked")){
							Check.push($("table").find("input").eq(i).attr("num"))
						}
					}
					
					$.ajax({
						type:"get",
						url:"https://www.retux.cn/MgUserSendCouponSubmit",
						async:true,
						data:{
							Id:Check.join("-"),
							UserNo:orderNum
							
						},
						success:function(data){
							if(data=='success'){
								layer.msg('提交成功');
								parent.location.reload();
							}else{
								layer.msg('提交失败');
							}
							
						}
					});
				})
		}else{//查看用户所有优惠券
			$('.save_btn').css('display','none');
			$.ajax({
				type:"get",
				url:"https://www.retux.cn/MgUserCouponDetail",
				async:true,
				data:{
					UserNo:orderNum
				},
				success:function(data){
					for (var i=0;i<data.length;i++) {
						var Tr = `
						<tr> 
							<td>${data[i][0]}</td>
							<td>${data[i][1]}</td>
							<td>${data[i][2]}</td>
							<td>${data[i][3]}</td>
						</tr>
						
					`;
					$("tbody").append(Tr)
					}
					
					
				}
			});
		}
		

</script>